devtools::install_github("gledguri/QM",dependencies = TRUE, force = T )
library(QM)
load_QM_packages()Quantitative Metabarcoding
If you end up using any of the following model please cite Guri et al., 2024 for models 1 and 2. For models 3 - 5 please cite Guri et al., 2024
This package is designed to simplify complex mathematical processes, allowing researchers, resource managers, and technicians to analyze environmental DNA (eDNA) data without needing advanced mathematical expertise. By using Bayesian inference, the package helps estsimate eDNA concentration from field samples. This package is currently in beta development, and new features and improved documentation are ongoing. Please feel free to reach out with any questions or feedback.
This package includes 5 models that can be used individually or joined within 3 frames of inferences:
1. qPCR (M1 & M2)
2. Metabarcoding (M3 & M4)
3. qPCR + Metabarcoding (M5 which jointly estimates M1-M4)
Directed Acyclic Graph (DAG) of the model overview
First things first, load the package and its dependencies.
You can load your data but I have included a set of data in the package to work and play with.
# data(herring_qpcr);force(herring_qpcr) #extra data to play around with
data(cod_qpcr);force(cod_qpcr)
data(metabarcoding);force(metabarcoding)Let’s view the data
cod_qpcr# A tibble: 403 × 7
Well Sample_name Species Sample_type Ct Plate Std_concentration
<chr> <chr> <chr> <chr> <chr> <chr> <dbl>
1 A1 Std-CH1 Clupea harengus STANDARD 20.67928886 Plate_B 1000000
2 B1 Std-CH2 Clupea harengus STANDARD 24.28047562 Plate_B 100000
3 C1 Std-CH3 Clupea harengus STANDARD 27.46961784 Plate_B 10000
4 D1 Std-CH4 Clupea harengus STANDARD 30.63396072 Plate_B 1000
5 E1 Std-CH5 Clupea harengus STANDARD 34.198452 Plate_B 100
6 F1 Std-CH6 Clupea harengus STANDARD 36.77652359 Plate_B 10
7 G1 Std-CH7 Clupea harengus STANDARD 39.35696793 Plate_B 1
8 A2 Std-CH1 Clupea harengus STANDARD 20.85572815 Plate_B 1000000
9 B2 Std-CH2 Clupea harengus STANDARD 24.01898384 Plate_B 100000
10 C2 Std-CH3 Clupea harengus STANDARD 27.45393944 Plate_B 10000
# ℹ 393 more rows
metabarcoding# A tibble: 10 × 93
Species sp_idx ini_conc Mock_1 Mock_2 Mock_3 Mock_4 Mock_5 Mock_6 `2019629_11` `2019629_15` `2019629_16` `2019629_22` `2019629_28` `2019629_31` `2019629_32` `2019629_6` `2019629_7` `2020620_03` `2020620_04` `2020620_05` `2020620_06` `2020620_07` `2020620_08` `2020620_11` `2020620_12` `2020620_13` `2020620_14` `2020620_15` `2020620_16` `2020620_19` `2020620_20` `2020620_21` `2020620_22` `2020620_23` `2020620_24` `2020620_27` `2020620_28` `2020620_29` `2020620_30` `2020620_31` `2020620_32` `2021624_10` `2021624_11` `2021624_14` `2021624_15` `2021624_16` `2021624_17` `2021624_18` `2021624_19` `2021624_20` `2021624_21` `2021624_22` `2021624_25` `2021624_26` `2021624_27` `2021624_28` `2021624_29` `2021624_3` `2021624_30` `2021624_31` `2021624_32` `2021624_33` `2021624_36` `2021624_37` `2021624_38` `2021624_39` `2021624_4` `2021624_40` `2021624_41` `2021624_42` `2021624_43` `2021624_44` `2021624_5` `2021624_6` `2021624_7` `2021624_8` `2021624_9` `2019629_12` `2019629_13` `2019629_14` `2019629_19` `2019629_20` `2019629_21` `2019629_23` `2019629_24` `2019629_27` `2019629_29` `2019629_3` `2019629_30` `2019629_4` `2019629_5` `2019629_8`
<chr> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
1 Brosme brosme 1 6022 26537 26282 55800 37606 34698 82587 0 0 0 0 0 2 0 0 6 2 1782 0 2 0 0 0 2 0 2 0 0 2 0 0 2 0 0 0 0 0 2 0 0 0 0 10 2 0 6 0 0 2 0 0 2 0 2 2 4 0 10 0 4 0 2 0 0 0 0 0 0 6 0 0 0 0 0 2 2 0 0 1 0 0 0 7 2 0 0 2 0 0 1 0
2 Cyclopterus lumpus 2 12061 63611 38494 80634 58797 37921 95245 2 0 0 2 0 0 0 0 0 4 2 0 2 4 0 0 0 6 0 8 0 0 0 0 4 0 0 0 0 2 4 0 0 2 4 0 0 0 2 0 0 0 2 0 12 4 0 10 0 4 22 4 30 2 2 10 2 6444 0 2 0 1114 0 0 0 0 2 8 2 0 3 6 1 3 0 12 1 1 1 18 90138 2 0 4
3 Hippoglossoides platessoides 3 6812 103953 53527 96043 83638 50442 118507 8214 0 0 6890 2 0 2 13672 4 17624 20868 0 5686 10148 6574 350 0 6 22342 4 7552 24912 0 12842 17432 4 10 9522 34610 10024 27240 22970 10798 28 6 16172 0 0 8272 8308 8 13990 8 4340 244510 360158 113176 477728 233486 25768 510300 240732 543826 63728 85020 3722 20754 40130 3822 4332 15434 99374 30014 23738 0 1580 1512 5490 13680 1 10716 67511 20325 1203 1 13598 2 7871 18 21045 14509 9 6 3
4 Leptoclinus maculatus 4 3725 228228 124488 237519 194652 107854 256737 160 0 0 6800 0 0 0 5240 0 4 848 0 3274 746 0 0 0 0 0 2 0 0 0 0 254 0 0 0 0 0 3020 5034 0 2 2 2 0 0 0 0 0 0 2 0 1336 0 0 5584 2 2046 0 66 1024 0 2312 18044 2 1430 0 582 0 724 0 0 0 294 3372 2 0 1 5 21640 5 4 2 218 2 1 2 2016 22234 5348 4 0
5 Mallotus villosus 5 9816 72751 35851 94465 58157 31141 90112 70304 3100 6 4 10 0 10 1372 6580 242 2040 4 256 0 0 210 5816 436 15670 10472 2 780 4 4 26074 4454 15910 1640 7958 3552 20624 6072 2 3432 4750 26782 1502 496 4 2 14 4004 14 4 48540 10376 239346 39828 12914 12 9548 15520 98442 16534 6886 3704 6 2534 12 4 10 12658 8 6 4 7354 5094 74 3270 5 11 13 3 10 0 11 73 2 6 9830 3047 40385 860 226
6 Maurolicus muelleri 6 7087 99815 29082 130790 120742 58762 162580 0 0 0 0 2 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 2 0 0 2 0 0 0 0 4 0 0 0 0 1 3 0 0 3 0 0 0 1 0 0 3 1
7 Myoxocephalus scorpius 7 8908 75120 44139 77521 70449 48500 91900 0 0 0 2 0 0 0 0 0 6 4 0 0 2 10 0 2 2 0 2 0 2 0 0 4 0 0 2 0 0 0 2 2 2 0 4 0 2 0 0 0 2 0 0 4 2 0 2 6 2 14 4 10 0 0 2 0 4 2 2 0 18 0 0 0 0 0 2 0 0 1 2 0 0 0 2 0 0 1 6 3 2 0 0
8 Pholis gunnellus 8 4477 66110 36235 58501 52223 38270 75811 100 694 0 2936 2 834 0 9916 0 2446 3070 4 3306 5562 1146 0 0 2218 4 5542 3176 0 0 4 556 0 0 2428 0 9314 1448 2034 4 824 6954 14 2866 0 1702 0 2 0 2 0 1194 14 6 3068 574 2410 16 1388 2508 4 1094 8266 5300 4572 0 734 0 2678 0 0 2 830 1420 7630 1884 0 0 1 0 0 0 0 0 0 1 12 3 1 0 0
9 Pleuronectes platessa 9 2637 41550 19983 44716 44234 27283 63749 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
10 Zz_Gadus morhua 10 5942 72763 56460 111345 82212 52685 112193 8514 8 1752 4462 5630 4822 26164 78346 50714 50744 17520 2622 32848 44932 2036 272 22108 0 25250 2 0 25320 16498 1482 12430 20104 7386 3100 12350 0 14652 11836 4 22106 5912 70490 4274 8420 17494 8180 8 25790 12904 14 30104 23940 13508 65144 11634 17790 88546 15530 49048 6 32758 694 186 18264 8326 18766 4664 79992 4 5492 1652 17274 8860 4160 48536 3 6 23677 0 5 0 11638 4592 7772 36686 18466 20476 29841 8 2
Before you run any model
All the models are designed to be run in similar chain operations:
(1) Load model –> (2) Prepare data –> (3) Run model –> (4) Extract output –> (5) Plot output
- Load model is a function that load and compile the stan model into your local computer by running
load_model('Model number'). All the stan model are located in the github repository under folder Stan. Loading each model takes slightly less than 1 min.
- Prepare data are a set of functions that converts the data frame into a list that will be thereafter imputed when running the stan model (step 3). For running this function the data should be formatted in a particular form, distinguishing the different samples and their information. Please use
data_example('Model number')or usedata(cod_qpcr)ordata(metabarcoding)to see the data format for required for running prepare data functions. The output of this function is a list.
- Run Stan model is a function that calls the compiled stan model (step 1) and loads the prepared data (step 2) onto the model. The output of this function is a list containing 2 lists ([1] data list (created in step 2) and [2] stan model output). If you are interested in only looking at the output of the model you can pull out the second list
output_list[[2]]4. Extract output are a set of functions that extract the interested parameters from each specific model output (M1 - M5; step 3) hence the functions are tailored for each particular model output and stan model code. To have an overview of all functions please read through this document or check all functions
- Plot output are a set of functions that plot the interested parameters from each specific model output (M1 - M5; step 3 and 4) hence the functions are tailored for each particular model output and stan model code. To have an overview of all functions please read through this document or check all functions. These are standard plots I have created but feel free to generate any plot as you see fit; all model outputs can be extracted either by using
extract_param(model = output_list[[2]], par = 'parameter_name')or simply by printing outoutput_list[[2]]
1 Model 1
Before going to load and run Model 1 and 2 here’s a description of the model.
This model implements a two step model (joint model) to estimate the relationship between DNA concentration (C) and qPCR outcomes (Y and Z). The model jointly combines two compartments (eq. 1.1 - 2.3) to estimate DNA concentration using both Ct values (Y) and positive or negative qPCR amplification outcomes (Z). For detailed explanation please read Guri et al., 2024.
In short the presence (Z = 1) or absence (Z = 0) of qPCR amplification in sample \(i\) in technical replicate \(j\) is modeled as a Bernoulli random variable with the probability of amplification \(\theta_i\). The probability of amplification arises from a Poisson process with rate parameter \(\lambda\). The probability of having no amplification events is given by \(e^{-\lambda}\), and thus the probability of positive amplification is \(1-e^{-\lambda}\). We model \(\lambda\) as a function of concentration where \(\lambda = C \cdot \phi\). Hence \(\phi\) is the probability that a single target molecule in reaction will lead to a successful amplification event. In the ideal scenario when only one target molecule is in the reaction and it gets successfully amplified, \(\phi = 1\).
Additionally the second compartment models the observed Ct values (Y) in sample \(i\) in technical replicate \(j\) as random variable drawn from a Normal distribution with mean \(\mu\) and standard deviation \(\sigma\). We model \(\mu\) as a linear function of DNA concentration (C) with intercept and slope \(\beta0\) and \(\beta1\) (Equation 2.2). The standard deviation of the observed Y is an exponential function of DNA concentration with intercept and slope \(\gamma0\) and \(\gamma1\) (Equation 2.3). Note that \(\beta0\) (intercept between Ct and DNA concentration) has subscript \(_p\) meaning that is different for every plate. The reason for having a different \(\beta0\) is due to the qPCR machine being sensitive to external factors hence every qPCR run has a different \(\Delta\)Rn (normalized fluorescence signal).
\[ \begin{aligned} &\textbf{qPCR probability of detection model}\\ Z_{ij} &\sim \text{Bernoulli}(\theta_{i}) && \text{(1.1)} \\ \theta_{i} &= 1 - exp(-C_{i} \cdot \phi) && \text{(1.2)} \\ &\text{}\\ &\textbf{qPCR continuous model}\\ Y_{ij} &\sim \text{Normal}(\mu_{i}, \sigma_{i}) && \text{(2.1)} \\ \mu_{i} &= \beta0_{p} + \beta1 \cdot ln(C_{i}) && \text{(2.2)} \\ \sigma_{i} &= e^{(\gamma0 + \gamma1 \cdot ln(C_{i}))} && \text{(2.3)} \end{aligned} \]
1.1 Load the stan model
M1 <- load_model('M1')1.2 Prepare the data to be loaded in the model.
The data should be formatted in a particular form. Please use data_example('M1') to see the data format for required for Model 1 or use data(cod_qpcr) to load the data included in the package.
stan_data_M1 <- prep_stan_M1(
qpcr_data = cod_qpcr %>% filter(Sample_type=="STANDARD"),
Ct = "Ct",
standard_concentration = "Std_concentration",
plate_index = 'Plate')Plate index matches the total number of plates
1.3 Run the model.
This chunk runs the Bayesian model (eq. 1.1 - 2.3) using rstan where C is the known DNA concentration from the Standard samples, Y is the observed Ct values form the qPCR machine and Z (Z = 1 for positive amplification & Z = 0 for non amplification hence Ct == ‘Undetermined’).
All the unknown parameters of the model (all Greek letters such as \(\phi\), \(\beta0_p\), \(\beta1\), \(\gamma0\), \(\gamma1\), \(\mu\), \(\sigma\), \(\theta\)) are in stan model output and can be extracted by using extract_qpcr_param(model_output) see below. Note that \(\beta0\) (intercept between Ct and DNA concentration) has subscript \(_p\) meaning that is different for every plate. The reason for having a different \(\beta0\) is due to the qPCR machine being sensitive to external factors hence every qPCR run has a different \(\Delta\)Rn (normalized fluorescence signal).
M1_output <- Run_Model(stan_object = M1, stan_data = stan_data_M1)1.4 Extract outputs
Here is how you extract the important parameter of the model.
extract_qpcr_param(M1_output) parameter mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
1 logit_phi 3.2655964 0.010624183 0.89957876 1.5624832 2.635500 3.2466880 3.8672944 5.0603677 7169.474 1.000792
2 beta_0[Plate_B] 40.4302372 0.002777605 0.14674503 40.1384618 40.333587 40.4318662 40.5263019 40.7209564 2791.168 1.000566
3 beta_0[Plate_D] 40.6073329 0.002964096 0.15349828 40.3009045 40.506109 40.6106755 40.7096034 40.9047340 2681.776 1.000866
4 beta_0[Plate_E] 40.6064562 0.002954269 0.15250053 40.3036726 40.506343 40.6064725 40.7107942 40.9000254 2664.665 1.000695
5 beta_0[Plate_F] 40.7558762 0.002856701 0.14724821 40.4577252 40.659099 40.7571162 40.8546015 41.0416472 2656.872 1.000605
6 beta_0[Plate_G] 40.4669709 0.002839797 0.14604729 40.1750378 40.369469 40.4677861 40.5647193 40.7528371 2644.919 1.000589
7 beta_1 -1.4205626 0.000218899 0.01093621 -1.4419009 -1.428004 -1.4206727 -1.4133364 -1.3986527 2496.014 1.000762
8 gamma_0 0.7769381 0.001096160 0.08998344 0.6015650 0.716263 0.7759529 0.8374682 0.9570908 6738.724 1.000413
9 gamma_1 -0.2329509 0.000185929 0.01356744 -0.2589891 -0.242244 -0.2332533 -0.2241034 -0.2055092 5324.809 1.000086
1.5 Plot outputs
This chunk extracts the parameters (all Greek letters in eq. 1.1 - 2.3) and plots them in relation to observed values (Ct and Z). Two different plots are generated each representing the two model compartments, the probability of detection model (eq. 1.1 - 1.2) by running plot_qpcr_prob_det(M1_output), and the continuous model (eq. 2.1 - 2.3) by runningplot_qpcr_cont_mod(M1_output).
plot_qpcr_prob_det(M1_output)plot_qpcr_cont_mod(M1_output)plot_qpcr_curves(M1_output)Also I made a custom function that can plot the continuous model having the plates as the facet.
plot_qpcr_cont_mod_plate_specific(M1_output)2 Model 2
Model 2 builds on Model 1 by incorporating environmental samples (e.g., field-collected data) alongside standard samples. By sharing parameters learned from the standards (e.g., detection probabilities or Ct-concentration relationships with the known DNA concentration), it estimates the DNA concentration (C_est_log) for imputed field samples (Sample_name) with credible intervals (C_est_log_2.5%CI and C_est_log_97.5%CI). The estimated DNA concentration (C_est_log) from environmental samples can be extracted from the model output using extract_est_conc(M2_output) function see here. The mathematical notation is the same as Model 1 where 2 set of equations (eq 1.1 - 2.3) are used, one for standards and one for the unknown environmental samples where the only join information they share are the model parameters (all Greek letter).
2.1 Load the stan model
M2 <- load_model('M2')2.2 Prepare the data to be loaded in the model.
The data should be formatted in a particular form. Please use data_example('M2') to see the data format for required for Model 2 or use data(cod_qpcr) to load the data included in the package.
stan_data_M2 <- prep_stan_M2(
qpcr_data = cod_qpcr,
sample_type = "Sample_type",
Ct = "Ct",
sample_name_column = "Sample_name",
standard_concentration = "Std_concentration",
plate_index = 'Plate')Plate index matches the total number of plates
2.3 Run the model.
M2_output <- Run_Model(stan_object = M2, stan_data = stan_data_M2)2.4 Extract outputs
extract_qpcr_param(M2_output) parameter mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
1 logit_phi 2.9640542 0.007342989 0.942553803 1.2732079 2.2844346 2.9214003 3.5894045 4.9068002 16476.561 0.9999588
2 beta_0[Plate_B] 40.4324065 0.001860081 0.125927917 40.1850930 40.3478085 40.4328093 40.5165373 40.6754761 4583.320 1.0013875
3 beta_0[Plate_D] 40.6077916 0.001948796 0.131527276 40.3480773 40.5202744 40.6084860 40.6960764 40.8622016 4555.111 1.0013690
4 beta_0[Plate_E] 40.6092590 0.001939078 0.131595963 40.3503946 40.5217869 40.6100928 40.6974823 40.8700014 4605.688 1.0008204
5 beta_0[Plate_F] 40.7445673 0.001926504 0.127647661 40.4938013 40.6590198 40.7451504 40.8322436 40.9931820 4390.217 1.0012809
6 beta_0[Plate_G] 40.4666742 0.001861922 0.125575421 40.2173066 40.3820152 40.4678034 40.5514874 40.7128577 4548.691 1.0011179
7 beta_1 -1.4204159 0.000143349 0.009323798 -1.4386855 -1.4267290 -1.4204567 -1.4141958 -1.4020359 4230.532 1.0013252
8 gamma_0 0.6860174 0.000474065 0.056862769 0.5754386 0.6470654 0.6861991 0.7237400 0.7997116 14387.354 1.0003246
9 gamma_1 -0.2273482 0.000112986 0.012155448 -0.2502200 -0.2356510 -0.2277705 -0.2194703 -0.2025676 11574.241 1.0004711
extract_est_conc(M2_output) %>% as_tibble()# A tibble: 84 × 5
sample_index Sample_name C_est_log `C_est_log_2.5%CI` `C_est_log_97.5%CI`
<dbl> <chr> <dbl> <dbl> <dbl>
1 1 2019629_11 -0.189 -1.51 0.835
2 2 2019629_12 -0.738 -2.73 0.657
3 3 2019629_13 1.35 0.315 2.24
4 4 2019629_14 -3.37 -7.36 -0.627
5 5 2019629_15 -1.35 -3.32 0.0533
6 6 2019629_16 0.996 0.121 1.75
7 7 2019629_19 -1.01 -3.04 0.422
8 8 2019629_20 -3.16 -7.24 -0.396
9 9 2019629_21 -3.35 -7.38 -0.676
10 10 2019629_22 -1.02 -2.44 0.0882
# ℹ 74 more rows
2.5 Plot outputs of Model 2
plot_qpcr_curves(M2_output)plot_qpcr_prob_det(M2_output)plot_qpcr_cont_mod(M2_output)You could change the x limits by adding xmin_log and xmax_log arguments. The limits are in \(log_e\) hence xmax_log = \(8 = 3 \cdot 10^3\)
plot_qpcr_cont_mod(M2_output,xmin_log = 0,xmax_log = 8)plot_qpcr_cont_mod_plate_specific(M2_output)Here I provide a standard way of plotting the estimated DNA concentration of environmental (field) samples by putting the samples on x-axis and eDNA concentrations on y-axis. All the DNA concentrations at around \(10^{-1.3}\) and very large error bars are basically non-detects indicating that no targeted DNA was found in all technical replicate of the sample.
plot_est_conc(M2_output)3 Model 3
Here we establish that the number of observed reads (R) of each species \(s\) in sample \(i\) from metabarcoding sequencing is a draw from a Multinomial distribution given the proportions for each species \(\psi\) in each sample and the total number of reads (T) per that sample (eq 3.1). We formulate that \(\psi\) is the softmax transformation of \(\gamma\) the post-PCR log-ratio amplicon abundance (eq 3.2). The post-PCR log-ratio amplicon abundance \(\gamma\), is the known (pre-PCR) log-ratio DNA concentration (\(\eta\)) modified by the product of the ratio of amplification efficiencies \(\alpha\) for each taxa and the number of PCR cycles (\(NPCR\)) (eq 3.3).
\[ \begin{align*} R_{is}\ &\sim \text {Multinomial} \left(\psi_{is},\ T_i\right) && \text{(3.1)}\\ {\psi}_{is}&=\frac{e^{{\gamma}_{is}}}{\sum_{i=1}^{I}e^{\gamma_{is}}} && \text{(3.2)} \\ \gamma_{is}&=\eta_{is}+\left(NPCR\times\alpha_s\right) && \text{(3.3)} \\ \end{align*} \]
I know that log-ratio hurts people’s brain so here’s a development of the equation 3.3 to put into perspective.
\[ \begin{align*} \overbrace{\gamma_{is}}^\text{Post-PCR log-ratio}&= \overbrace{\eta_{is}}^\text{Pre-PCR log-ratio} + \overbrace{NPCR \cdot \alpha_s}^\text{log-ratio PCR amplification bias} \\ \\ ln\left(\frac{\pi_{is}}{\pi_{i,s=\text{ref}}}\right)&= ln\left(\frac{C_{is}}{C_{i,s=\text{ref}}}\right) + NPCR \cdot ln\left(\frac{1 + a_s}{1 + a_{s=\text{ref}}} \right)\\ \underbrace{\frac{\pi_{is}}{\pi_{i,s=\text{ref}}}}_{\text{Post-PCR ratio}} &= \underbrace{\frac{C_{is}}{C_{i,s=\text{ref}}}}_{\text{Pre-PCR ratio}} \cdot \underbrace{\left( \frac{1 + a_s}{1 + a_{s=\text{ref}}} \right)^{NPCR}}_{\text{PCR amplification factor}} \end{align*} \]
Let say that \(\pi / \pi_{\text{ref}}\) is the ratio of post-PCR amplicon proportional abundance \(s\) over the reference species hence post-PCR log-ratio abundance \(\gamma= ln(\pi / \pi_{\text{ref}})\). Example: if \(\pi_{s=1} = 0.2\) (20%) and \(\pi_{s=ref} = 0.1\) (10%) then the ratio would be 2 hence the post-PCR log-ratio abundance would be \(\gamma_s = ln(2) = 0.7\). Let’s say \(C /C_{\text{ref}}\) is the pre-PCR amplicon abundance \(s\) over the reference species hence pre-PCR log-ratio amplicon abundance \(\eta = ln(C /C_{\text{ref}})\) . Example: if \(C_{s=1}=3\) and \(C_{s=ref}=1\) then the ratio would be 3 hence the post-PCR log-ratio abundance would be \(\eta_s = ln(3) = 1.1\). Let’s say that \((1+a_s) / (1+a_{s=\text{ref}})\) is the amplification efficiency of amplicon \(s\) over the reference species per each PCR cycle hence the log-ratio amplification efficiency \(\alpha_s = ln((1+a_s) / (1+a_{s=\text{ref}}))\). Example: if \(a_{s=1} = 0.001\) and \(a_{s=\text{ref}} = 0.01\) then the ratio of PCR-bias would be \((0.99)^{NPCR}\) meaning that the \(s=1\) amplicon will amplify at a 0.99 rate compared to the reference species for each PCR cycle. For making easier computation we write that rate as log-ratio rate hence \(\alpha = ln(0.99) = -0.01\). Now if you plug in the number in the example you should get something like this:
\[ \frac{0.2}{0.1} = \frac{3}{1} \cdot \left(\frac{1+0.001}{1+0.01} \right)^{40} \]
Since we know the pre-PCR (initial) concentration when using a mock community and we can derive the post-PCR proportions using the model (eq 3.1 - 3.3) we can estimate the amplification efficiency for each species (always) relative to a reference species.
3.1 Load the stan model
M3 <- load_model('M3')3.2 Prepare the data to be loaded in the model.
The data should be formatted in a particular form. Please use data_example('M3') to see the data format for required for Model 3 or use data(metabarcoding) to load the data included in the package and select the columns that belong to the mock community.
Important! Please assign ‘Zz_’ before the name of the reference species and assign it on the last row on the metabarcoding dataframe.
An additional feature is the alpha magnitude where the user can indicate the standard deviation of a Normal distribution with mean 0 (prior distribution) for \(\alpha\) parameter. This is left on purpose to be adjusted by the users as not all data are similar. On default alpha = 0.1 but to put values in perspective alpha values = |0.1| indicates a 4 fold difference between pre- and post-PCR (typical 40 cycles) relative to the reference species. Typical alpha values for 12S MiFish primers are < |0.03|.
# Trim metabarcoding data only for mock samples
moc_dat <- metabarcoding %>% select(Species,sp_idx,ini_conc,Mock_1:Mock_6)
# # Prepare the data for going into the model
stan_data_M3 <- prep_stan_M3(
metabarcoding_data = moc_dat,
mock_sequencing_columns = c('Mock_1','Mock_2','Mock_3','Mock_4','Mock_5','Mock_6'),
mock_initial_concentration = 'ini_conc',
species_index = 'sp_idx',
species_names = 'Species',
number_of_PCR = 43,
alpha_magnitude = 0.1)3.3 Run the model
M3_output <- Run_Model(stan_object = M3, stan_data = stan_data_M3)3.4 Extract outputs
These two functions extract the amplification efficiency from the Model 3 (eq 3.3). The function extract_amp_efficiecy extracts the values of \(\alpha_s\) parameter with 95% credible intervals (CI). Note that the values are in additive log-ratios and the reference species = 0 (\(ln(1) = 0\). Each alpha value can be interpreted as the log-difference of amplification efficiency of the species relative to the reference species per each PCR cycle. Any negative value would be indicating less efficient amplification than the reference species and positive values vice-versa. Let’s say a value -0.015 is indicating that the species is amplifying -0.015 times less ‘efficient’ per each PCR cycle than that of the reference species.
The function amp_eff_output_extract creates a data frame that puts things in perspective by extracting and computing the values on Equation 3.3
extract_amp_efficiecy(M3_output) Species sp_idx alpha alpha_2.5%_CI alpha_97.5%_CI
1 Brosme brosme 1 -0.014625261 -0.014735369 -0.014518937
2 Cyclopterus lumpus 2 -0.022591229 -0.022689644 -0.022494915
3 Hippoglossoides platessoides 3 -0.002313858 -0.002403553 -0.002223342
4 Leptoclinus maculatus 4 0.030801119 0.030722626 0.030877989
5 Mallotus villosus 5 -0.017323844 -0.017421586 -0.017225278
6 Maurolicus muelleri 6 0.000792141 0.000704310 0.000880210
7 Myoxocephalus scorpius 7 -0.013584659 -0.013680406 -0.013489733
8 Pholis gunnellus 8 -0.002699871 -0.002802792 -0.002594078
9 Pleuronectes platessa 9 0.002551490 0.002439548 0.002663176
10 Zz_Gadus morhua 10 0.000000000 0.000000000 0.000000000
amp_eff_output_extract(M3_output) Species Pre-PCR Post-PCR ALR Post-PCR_est Post-PCR_est_2.5%_CI Post-PCR_est_97.5%_CI
1 Brosme brosme 0.08923200 0.05556938 0.01337365 0.05556949 0.05550366 0.05562740
2 Cyclopterus lumpus 0.17871590 0.07901771 0.70793133 0.07901640 0.07896248 0.07906469
3 Hippoglossoides platessoides 0.10093796 0.10672923 0.13663999 0.10672880 0.10669596 0.10676741
4 Leptoclinus maculatus 0.05519582 0.24240363 -0.46697893 0.24240652 0.24244869 0.24235196
5 Mallotus villosus 0.14545023 0.08065732 0.50196793 0.08065571 0.08060300 0.08071282
6 Maurolicus muelleri 0.10501282 0.12690236 0.17621634 0.12690330 0.12687442 0.12693585
7 Myoxocephalus scorpius 0.13199579 0.08596141 0.40490397 0.08596245 0.08591364 0.08600986
8 Pholis gunnellus 0.06633870 0.06898988 -0.28309260 0.06898989 0.06892945 0.06906019
9 Pleuronectes platessa 0.03907419 0.05093104 -0.81240387 0.05093026 0.05086590 0.05099508
10 Zz_Gadus morhua 0.08804659 0.10283804 0.00000000 0.10283718 0.10320281 0.10247475
3.5 Plot outputs
plot_amp_eff(M3_output)4 Model 4
Model 4 is a continuation of Model 3 by incorporating environmental samples (e.g., field-collected data) alongside mock commuinty samples. By sharing the \(\alpha\) parameter learned from the mock community, it estimates the pre-PCR (initial) relative abundance for imputed field samples (Sample_name). The estimated initial DNA relative abundance from environmental samples can be extracted from the model output using extract_ini_prop(M4_output) function see here. The mathematical notation is the same as Model 3 where 2 set of equations (eq 3.1 - 3.3) are used, one for mock community and one for the unknown environmental samples where the only join information they share is the alpha parameter.
4.1 Load the stan model
M4 <- load_model('M4')4.2 Prepare the data to be loaded in the model.
The data should be formatted in a particular form. Please use data_example('M4') to see the data format for required for Model 4 or use data(metabarcoding) to load the data included in the package.
Important! Please assign ‘Zz_’ before the name of the reference species and assign it on the last row on the metabarcoding dataframe.
An additional feature is the ini_prop_mu and ini_prop_sd that can be added as arguments in prep_stan_M4. These 2 parameter are the mean (ini_prop_mu) and the standard deviation (ini_prop_sd) of the \(\eta\) initial (pre-PCR) abundances prior distribution wichi follows a Normal distribution. By default these values are ini_prop_mu = 0 and ini_prop_sd = 5 indicating that \(\eta \sim \mathcal{N}(0,5)\) and has a lower boundry at \(-30\) indicating that initial DNA concnetration log-ratios can not be lower than \(e^{-30} \approx 10^{-15}\). This is left on purpose to be adjusted by the users as this prior is not very informative hence users should adjust based on the prior knowledge on the nature of the data. To put values in perspective eta values = |2| or |4| indicates an 8 or 80 fold difference respectively between initial (pre-PCR) abundance between the species \(s\) and the reference species.
# Get column names for mock samples and environmental samples
mock_columns <- metabarcoding %>% select(Mock_1:Mock_6) %>% names()
sample_columns <- metabarcoding %>% select(-all_of(mock_columns),-Species,-sp_idx,-ini_conc) %>% names()
# Prepare the data for going into the model
stan_data_M4 <- prep_stan_M4(
metabarcoding_data = metabarcoding,
mock_sequencing_columns = mock_columns,
sample_sequencing_columns = sample_columns,
mock_initial_concentration = 'ini_conc',
species_index = 'sp_idx',
species_names = 'Species',
number_of_PCR = 43,
alpha_magnitude = 0.1)4.3 Run the model
M4_output <- Run_Model(stan_object = M4, stan_data = stan_data_M4)4.4 Extract outputs
These set of functions are extracting the same parameter as in Model 3. An additional function here is extract_ini_prop which extracts the pre-PCR (initial) proportions for each amplicon imputed. The output is a data frame where columns are field (unknown) samples and rows are species.
extract_amp_efficiecy(M4_output) Species sp_idx alpha alpha_2.5%_CI alpha_97.5%_CI
1 Brosme brosme 1 -0.014634634 -0.014746782 -0.014523563
2 Cyclopterus lumpus 2 -0.022599453 -0.022695886 -0.022499185
3 Hippoglossoides platessoides 3 -0.002321080 -0.002411995 -0.002230867
4 Leptoclinus maculatus 4 0.030793023 0.030715363 0.030869099
5 Mallotus villosus 5 -0.017330508 -0.017427557 -0.017233285
6 Maurolicus muelleri 6 0.000783467 0.000696472 0.000869281
7 Myoxocephalus scorpius 7 -0.013593885 -0.013691498 -0.013497533
8 Pholis gunnellus 8 -0.002707657 -0.002810763 -0.002605820
9 Pleuronectes platessa 9 0.002541421 0.002426333 0.002654796
10 Zz_Gadus morhua 10 0.000000000 0.000000000 0.000000000
amp_eff_output_extract(M4_output) Species Pre-PCR Post-PCR ALR Post-PCR_est Post-PCR_est_2.5%_CI Post-PCR_est_97.5%_CI
1 Brosme brosme 0.08923200 0.05556938 0.01337365 0.05556474 0.05549417 0.05563426
2 Cyclopterus lumpus 0.17871590 0.07901771 0.70793133 0.07901355 0.07896654 0.07907566
3 Hippoglossoides platessoides 0.10093796 0.10672923 0.13663999 0.10672955 0.10669136 0.10676727
4 Leptoclinus maculatus 0.05519582 0.24240363 -0.46697893 0.24239911 0.24245051 0.24233742
5 Mallotus villosus 0.14545023 0.08065732 0.50196793 0.08065821 0.08060808 0.08071104
6 Maurolicus muelleri 0.10501282 0.12690236 0.17621634 0.12689627 0.12687224 0.12691711
7 Myoxocephalus scorpius 0.13199579 0.08596141 0.40490397 0.08595565 0.08590014 0.08600873
8 Pholis gunnellus 0.06633870 0.06898988 -0.28309260 0.06898870 0.06892787 0.06904758
9 Pleuronectes platessa 0.03907419 0.05093104 -0.81240387 0.05092438 0.05085327 0.05099314
10 Zz_Gadus morhua 0.08804659 0.10283804 0.00000000 0.10286984 0.10323583 0.10250778
extract_ini_prop(M4_output) Species 2019629_11 2019629_12 2019629_13 2019629_14 2019629_15 2019629_16 2019629_19 2019629_20 2019629_21 2019629_22 2019629_23 2019629_24 2019629_27 2019629_28 2019629_29 2019629_3 2019629_30 2019629_31 2019629_32 2019629_4 2019629_5 2019629_6 2019629_7 2019629_8 2020620_03 2020620_04 2020620_05 2020620_06 2020620_07 2020620_08 2020620_11 2020620_12 2020620_13 2020620_14 2020620_15 2020620_16 2020620_19 2020620_20 2020620_21 2020620_22 2020620_23 2020620_24 2020620_27 2020620_28 2020620_29 2020620_30 2020620_31 2020620_32 2021624_10 2021624_11 2021624_14 2021624_15 2021624_16 2021624_17 2021624_18 2021624_19 2021624_20 2021624_21 2021624_22 2021624_25 2021624_26 2021624_27 2021624_28 2021624_29 2021624_3 2021624_30 2021624_31 2021624_32 2021624_33 2021624_36 2021624_37 2021624_38 2021624_39 2021624_4 2021624_40 2021624_41 2021624_42 2021624_43 2021624_44 2021624_5 2021624_6 2021624_7 2021624_8 2021624_9
1 Brosme brosme 1.412646e-06 0.002076188 3.252596e-06 1.689246e-05 5.996793e-06 9.954875e-05 4.346933e-07 2.663555e-05 0.0009046514 1.190290e-05 4.747212e-04 7.210779e-04 1.409659e-05 3.922389e-05 8.041224e-06 5.576264e-05 9.207993e-07 5.925549e-04 1.085303e-05 2.497972e-06 6.476740e-04 2.982530e-06 1.698392e-04 4.695947e-05 4.884198e-05 6.438679e-02 6.879404e-05 8.063592e-05 4.612253e-06 1.684736e-05 1.143190e-04 1.023547e-04 3.518875e-06 4.279306e-05 9.144060e-07 6.335645e-07 6.494159e-05 1.578191e-05 1.083809e-05 4.017453e-05 8.918778e-06 5.451956e-06 9.555325e-06 3.565747e-06 4.485278e-07 3.865932e-05 4.446814e-06 2.743530e-06 8.955473e-06 9.141310e-06 1.273258e-04 3.167415e-04 2.488578e-05 3.803878e-04 1.340524e-05 0.0009059983 7.184386e-05 1.920328e-05 1.063874e-05 8.817967e-06 5.914920e-07 5.394080e-06 5.289253e-06 2.401980e-05 5.472079e-06 2.736502e-05 8.296479e-07 8.459951e-06 3.829157e-07 2.491306e-05 5.432240e-06 3.754595e-06 2.835755e-06 1.829556e-05 1.050241e-05 9.553065e-06 4.915445e-05 9.919582e-07 6.853976e-06 1.064652e-04 7.466851e-06 9.812101e-06 1.811221e-04 4.941042e-05
2 Cyclopterus lumpus 2.921862e-05 0.002584767 5.603769e-04 1.478720e-04 7.462096e-06 1.272458e-04 6.085401e-05 4.862219e-03 0.0009963069 2.787716e-04 1.157473e-03 4.869383e-04 1.425997e-04 5.070537e-05 6.662429e-05 7.439226e-04 8.298210e-01 4.848486e-05 1.355321e-05 4.276599e-05 2.921867e-05 3.895569e-06 6.356654e-06 1.873941e-02 1.380945e-04 9.434209e-05 9.569506e-05 1.122173e-04 1.633243e-04 2.246093e-05 1.375790e-04 1.026622e-05 4.142129e-03 4.551967e-06 6.909655e-04 7.709767e-07 6.717592e-06 2.093520e-05 1.412444e-05 1.153304e-04 1.111734e-05 7.236191e-06 1.309011e-05 4.950673e-06 1.320807e-04 1.110063e-04 6.133591e-06 3.161411e-06 1.633241e-04 4.224346e-04 3.010137e-06 2.587026e-05 3.284105e-05 1.700849e-04 1.803522e-05 0.0012535125 7.220236e-06 3.772545e-04 1.449314e-05 7.695810e-05 2.278677e-05 5.381065e-07 3.806082e-05 1.090249e-06 2.027930e-04 8.562083e-05 3.174946e-05 9.143617e-05 3.851414e-05 3.480667e-05 9.514643e-04 1.520229e-04 1.881805e-01 2.392979e-05 2.015044e-04 1.342070e-05 1.321871e-02 1.131794e-06 9.036050e-06 1.361145e-04 9.398695e-06 2.032381e-04 1.073849e-03 6.876138e-05
3 Hippoglossoides platessoides 5.471252e-02 0.057786839 9.969586e-01 7.167387e-01 3.963998e-06 6.511946e-05 9.995475e-01 9.768932e-01 0.5456680316 4.426727e-01 5.608285e-01 4.301753e-04 5.279569e-01 3.585648e-04 5.362224e-04 3.688524e-01 5.585430e-02 2.359232e-05 8.061156e-05 8.372801e-05 3.320388e-03 1.387449e-01 6.640381e-05 5.625399e-03 2.649507e-01 4.442527e-01 4.611340e-05 1.419239e-01 1.790997e-01 6.851396e-01 3.518827e-01 4.907184e-06 1.741596e-03 2.976021e-01 1.359383e-04 7.003437e-01 5.051225e-01 1.021268e-05 9.048918e-01 2.205527e-01 1.450460e-04 2.635889e-04 5.312588e-01 5.677506e-01 3.816141e-01 3.320534e-01 4.731909e-01 9.989118e-01 1.014014e-03 2.699662e-04 1.233833e-01 1.243183e-05 1.626060e-05 3.199336e-01 5.287164e-01 0.1850683616 3.111024e-01 6.647606e-04 9.958859e-01 6.682742e-01 8.967305e-01 1.945339e-01 7.741352e-01 8.672245e-01 5.746262e-01 8.382831e-01 8.422554e-01 6.982799e-01 6.689233e-01 6.566799e-01 1.538837e-01 7.883909e-01 4.899974e-01 3.357611e-01 1.950102e-01 7.845736e-01 4.931693e-01 9.994426e-01 8.266172e-01 6.781908e-05 4.913013e-02 7.026842e-02 3.196364e-01 2.080228e-01
4 Leptoclinus maculatus 2.561441e-04 0.014830983 1.026144e-04 5.531725e-02 1.537172e-06 1.978550e-05 5.276755e-05 7.011370e-04 0.4450665436 1.051997e-01 2.161408e-03 1.049872e-04 1.584804e-05 7.345644e-06 1.428822e-05 8.508661e-03 2.060645e-02 7.219706e-06 1.945224e-06 1.222594e-02 5.250699e-04 1.280225e-02 8.351925e-07 1.335480e-05 1.418216e-05 4.344686e-03 1.393991e-05 1.967627e-02 3.169093e-03 3.380794e-06 2.311743e-05 1.483645e-06 1.110284e-06 6.203392e-07 1.501325e-05 2.248054e-07 9.338813e-07 2.873618e-06 2.198423e-06 7.727101e-04 1.706423e-06 1.056861e-06 1.953767e-06 6.953752e-07 1.405880e-07 8.862097e-03 2.497024e-02 7.456651e-07 1.707824e-05 2.126440e-05 3.657603e-06 3.814053e-06 4.632394e-06 1.730358e-06 2.592764e-06 0.0002451862 1.021070e-06 4.009641e-05 2.646319e-06 8.789328e-04 1.134264e-07 7.492788e-08 2.178345e-03 1.721910e-06 1.098107e-02 8.836323e-08 5.541138e-05 3.164514e-04 9.827416e-08 4.298769e-03 1.796436e-01 1.635293e-05 4.203600e-03 3.518753e-06 6.301691e-03 1.890124e-06 8.648564e-04 2.451508e-07 1.321695e-06 2.021243e-05 2.199862e-03 3.775209e-02 2.655130e-05 7.631948e-07
5 Mallotus villosus 8.930098e-01 0.789286420 1.852318e-03 2.587884e-04 8.925976e-01 6.858405e-03 2.260593e-04 1.464906e-02 0.0009499966 4.617339e-04 8.444415e-04 3.224346e-02 2.361149e-04 3.636123e-03 3.365885e-04 3.285338e-01 2.236186e-02 4.158697e-05 7.883205e-04 7.311869e-01 9.903932e-01 2.654395e-02 2.146315e-01 9.720151e-01 6.927823e-03 8.279505e-02 3.002474e-03 1.217152e-02 5.194154e-06 1.834086e-05 4.021372e-01 3.565741e-01 2.672704e-01 3.979565e-01 7.791886e-01 2.521713e-04 3.014340e-02 4.918486e-04 5.036321e-04 6.289934e-01 3.181860e-01 8.192548e-01 1.744219e-01 2.489077e-01 2.577966e-01 4.793547e-01 2.385213e-01 2.715336e-04 2.385816e-01 4.213920e-01 3.896267e-01 2.968481e-01 1.103777e-01 2.808001e-04 2.220409e-04 0.6308760060 1.697683e-01 2.234931e-03 1.539794e-03 2.529623e-01 4.926277e-02 7.844426e-01 1.230528e-01 9.144559e-02 5.004208e-04 2.990528e-02 1.035311e-01 2.410151e-01 3.309502e-01 1.014139e-01 2.919663e-01 4.068033e-04 5.898968e-02 1.967304e-03 3.289457e-04 9.449070e-04 1.197752e-01 4.709944e-04 3.791262e-04 4.736313e-03 4.361807e-01 4.516581e-01 8.176047e-03 9.480168e-02
6 Maurolicus muelleri 7.946274e-07 0.001382285 2.060726e-06 9.080021e-06 3.892788e-06 6.008297e-05 1.035108e-04 1.727635e-05 0.0007179248 6.793584e-06 1.032789e-04 2.542607e-05 7.867376e-06 3.181715e-04 4.476918e-06 1.457192e-05 5.448324e-07 2.059007e-05 6.145950e-06 1.331995e-06 1.368587e-03 1.691789e-06 2.895398e-05 1.192156e-03 2.544953e-05 2.933909e-06 4.246490e-05 3.660217e-06 2.796629e-06 1.026609e-05 6.600476e-05 4.269295e-06 2.245311e-06 1.940689e-06 6.259532e-07 4.544110e-07 2.896844e-06 8.720386e-06 6.294509e-06 1.573393e-06 5.209586e-06 3.065195e-06 5.649799e-06 2.020442e-06 3.126998e-07 2.024692e-05 2.609569e-06 1.777458e-06 6.047978e-05 5.328685e-06 1.239185e-06 1.096743e-05 1.432668e-05 5.174943e-06 7.709265e-06 0.0006019601 3.105353e-06 1.059914e-05 6.804279e-06 4.006826e-07 3.502003e-07 2.189681e-07 2.763574e-06 6.033809e-06 3.114271e-06 2.733750e-07 4.584182e-07 1.956005e-07 2.316560e-07 1.119847e-06 3.248131e-06 2.296631e-06 1.654076e-06 1.434161e-04 6.159840e-06 5.469889e-06 8.524158e-06 6.065016e-07 4.005450e-06 6.214512e-05 4.160578e-06 1.550952e-04 6.243511e-06 2.332459e-06
7 Myoxocephalus scorpius 1.366991e-06 0.002006386 9.798350e-05 3.243692e-05 5.663617e-06 9.339317e-05 4.377412e-07 2.482300e-05 0.0009389527 1.906445e-04 1.245330e-04 4.251690e-05 1.318292e-05 3.814290e-05 4.687218e-05 1.650542e-04 1.780769e-05 3.529335e-05 1.028635e-05 2.953510e-05 2.183198e-05 2.857451e-06 4.465380e-06 4.371684e-05 1.432517e-04 1.328659e-04 6.962340e-05 6.245002e-06 5.475049e-05 1.640060e-03 1.029610e-04 9.821711e-05 7.650275e-04 3.165860e-06 9.758547e-05 6.251175e-07 6.202505e-05 1.503073e-05 1.101060e-05 7.842417e-05 8.999759e-06 5.393014e-06 1.642366e-04 3.610509e-06 4.354113e-07 2.746047e-06 6.247603e-05 2.332706e-04 1.100917e-04 8.929343e-06 4.773189e-05 1.857583e-05 3.494092e-04 8.658069e-06 1.256602e-05 0.0008799368 6.829470e-05 1.816235e-05 1.018251e-05 1.727318e-05 7.629130e-06 3.760938e-07 5.072667e-06 3.505087e-05 6.788624e-05 3.680115e-05 2.172495e-05 2.052258e-05 3.696565e-07 1.892141e-06 1.175894e-04 3.506435e-06 7.601894e-05 2.636268e-04 1.368514e-04 9.367791e-06 1.438643e-04 9.284972e-07 6.604434e-06 1.012878e-04 6.852851e-06 9.456834e-06 1.704437e-04 3.990915e-06
8 Pholis gunnellus 6.748875e-04 0.001607480 2.419913e-06 1.039323e-05 1.064794e-01 6.430735e-05 3.206078e-07 1.950576e-05 0.0007959428 1.918074e-01 5.759373e-06 2.820353e-05 8.780361e-06 3.645238e-04 2.985825e-05 2.099386e-04 1.125641e-05 1.625951e-01 6.815848e-06 9.265520e-06 1.627503e-05 1.023272e-01 2.948900e-06 3.250891e-05 3.737113e-02 6.645390e-02 1.608409e-03 8.390730e-02 9.981909e-02 1.213520e-01 6.911344e-05 4.948874e-06 7.259954e-01 5.227890e-05 2.198043e-01 2.993914e-01 3.237973e-06 9.963280e-06 2.690073e-04 7.147350e-03 5.691277e-06 3.677582e-06 1.377024e-01 2.426987e-06 3.604440e-01 1.793806e-02 4.260286e-02 3.313024e-04 3.053981e-02 3.290096e-01 1.074835e-04 3.020386e-01 1.547488e-05 6.692455e-02 8.526452e-06 0.0400746661 3.542910e-06 1.640761e-04 7.583882e-06 3.318500e-03 3.496647e-05 1.009863e-05 5.054542e-03 2.165736e-03 5.463125e-02 2.638338e-05 4.936559e-03 3.273987e-03 3.758427e-05 8.588644e-03 3.475124e-01 2.046859e-01 5.676337e-02 1.214024e-05 3.357863e-02 6.236150e-06 1.351119e-02 7.048452e-07 4.319503e-06 1.216630e-03 2.623925e-02 6.713020e-02 4.516426e-01 2.912003e-02
9 Pleuronectes platessa 7.469180e-07 0.001339304 1.930217e-06 1.365034e-06 3.564571e-06 5.578759e-05 2.847398e-07 1.659726e-05 0.0007022949 6.697169e-06 4.771331e-06 2.357260e-05 7.470574e-06 2.030343e-05 4.107784e-06 2.191196e-06 4.784392e-07 1.941420e-05 5.585945e-06 1.251017e-06 1.421522e-05 1.589999e-06 2.541067e-06 3.018956e-05 2.225911e-06 2.603475e-06 3.889540e-05 3.551047e-06 2.472003e-06 9.120441e-06 6.172524e-05 4.300649e-06 2.278388e-06 1.754714e-06 6.072978e-07 4.492980e-07 2.766777e-06 8.324095e-06 5.940629e-06 1.484643e-06 4.847149e-06 2.928944e-06 5.441354e-06 2.012417e-06 2.896351e-07 1.525830e-06 2.473696e-06 1.699223e-06 4.645417e-06 4.897235e-06 1.150933e-06 1.025511e-05 1.305331e-05 4.839956e-06 7.500700e-06 0.0005551285 2.909900e-06 1.047231e-05 6.187210e-06 3.655115e-07 3.157173e-07 2.054317e-07 2.512632e-07 4.394544e-07 2.982636e-06 2.526920e-07 4.365756e-07 1.829662e-07 2.285439e-07 1.053397e-06 2.993897e-06 2.168280e-06 1.545300e-06 9.883175e-06 5.803939e-06 5.311743e-06 7.605044e-07 6.079427e-07 3.678707e-06 5.844514e-05 3.990995e-06 5.292910e-06 5.921889e-06 2.174307e-06
10 Zz_Gadus morhua 5.131309e-02 0.127099350 4.184464e-04 2.274673e-01 8.909488e-04 9.925563e-01 7.830451e-06 2.789530e-03 0.0032593548 2.593636e-01 4.342951e-01 9.658936e-01 4.715972e-01 9.951669e-01 9.989529e-01 2.929138e-01 7.132543e-02 8.366162e-01 9.990759e-01 2.564168e-01 3.663562e-03 7.195687e-01 7.850861e-01 2.261237e-03 6.903783e-01 3.375341e-01 9.950136e-01 7.421147e-01 7.176789e-01 1.917879e-01 2.454053e-01 6.431952e-01 7.628422e-05 3.043343e-01 6.542445e-05 9.570627e-06 4.645906e-01 9.994163e-01 9.428514e-02 1.422968e-01 6.816225e-01 1.804528e-01 1.564169e-01 1.833224e-01 1.160231e-05 1.616176e-01 2.206366e-01 2.419632e-04 7.295000e-01 2.488564e-01 4.866984e-01 4.007146e-01 8.891514e-01 6.122902e-01 4.709912e-01 0.1395392439 5.189713e-01 9.964604e-01 2.515770e-03 7.446225e-02 5.393998e-02 2.100665e-02 9.552764e-02 3.909577e-02 3.589788e-01 1.316348e-01 4.916631e-02 5.699376e-02 4.905754e-05 2.289551e-01 2.591326e-02 6.336318e-03 2.017834e-01 6.617968e-01 7.644197e-01 2.144303e-01 3.592585e-01 8.118713e-05 1.729679e-01 9.934946e-01 4.862182e-01 3.728083e-01 2.190808e-01 6.679280e-01
4.5 Plot outputs
plot_amp_eff(M4_output)bar_plot_est_ini_prop(M4_output)5 Model 5
Model 5 addresses the proportionality limitation of Model 4 by incorporating absolute DNA concentration estimates for the reference species (\(C_{i,s=\text{ref}}\)) derived from Model 2 (e.g., qPCR-based absolute quantification of the reference species). By leveraging the absolute DNA concentration of the reference species from model 2 we can break the compositional “closed-sum” constraint, allowing absolute quantification of all the species that have an amplification efficiency value (\(\alpha\)). Here re-write the additive log-ratio as the difference between log initial concentration to the reference species (eq 3.4).
\[ \begin{align*} {\gamma}_{is}&= ln\left(\frac{C_{is}}{C_{i,s=\text{ref}}}\right) + NPCR \cdot \alpha &&\text{3.3} \\ {\gamma}_{is}&= ln(C_{is})-ln(C_{i,s=\text{ref}}) + NPCR \cdot \alpha &&\text{3.4} \\ \end{align*} \]
5.1 Load the stan model
M5 <- load_model('M5')5.2 Prepare the data to be loaded in the model.
The data should be formatted in a particular form. Please use data_example('M5') to see the data format for required for Model 5 or use data(cod_qpcr) and data(metabarcoding) to load the data included in the package.
Important! Please assign ‘Zz_’ before the name of the reference species and assign it on the last row on the metabarcoding dataframe.
mock_columns <- metabarcoding %>% select(Mock_1:Mock_6) %>% names()
sample_columns <- metabarcoding %>% select(-all_of(mock_columns),-Species,-sp_idx,-ini_conc) %>% names()
stan_data_M5 <- prep_stan_M5(
qpcr_data = cod_qpcr,
sample_type = "Sample_type",
Ct = "Ct",
sample_name_column = "Sample_name",
standard_concentration = "Std_concentration",
plate_index = 'Plate',
metabarcoding_data = metabarcoding,
mock_sequencing_columns = mock_columns,
sample_sequencing_columns = sample_columns,
mock_initial_concentration = 'ini_conc',
species_index = 'sp_idx',
species_names = 'Species',
number_of_PCR = 43,
alpha_magnitude = 0.1)5.3 Run the model
This model is slightly more expensive computationally compared to the other models. Often times the default treedeoth is exceeded hence limiting the perfect exploration of the parameter space for assuring the model posterior likelihood has converged. Here is advisable to add the argument treedepth = 12. The model output can be diagnosed by using diagnose_model(model_output) and check
M5_output <- Run_Model(stan_object = M5, stan_data = stan_data_M5,
treedepth = 12,iterations = 2000,warmup = 1000)Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#bulk-ess
5.4 Extract outputs
extract_amp_efficiecy(M5_output) Species sp_idx alpha alpha_2.5%_CI alpha_97.5%_CI
1 Brosme brosme 1 -0.014633818 -0.014742129 -0.014524649
2 Cyclopterus lumpus 2 -0.022597662 -0.022696633 -0.022502439
3 Hippoglossoides platessoides 3 -0.002320875 -0.002411496 -0.002230160
4 Leptoclinus maculatus 4 0.030793993 0.030717494 0.030872523
5 Mallotus villosus 5 -0.017330204 -0.017430045 -0.017232626
6 Maurolicus muelleri 6 0.000784127 0.000697908 0.000872216
7 Myoxocephalus scorpius 7 -0.013592820 -0.013685730 -0.013500918
8 Pholis gunnellus 8 -0.002707588 -0.002812167 -0.002604303
9 Pleuronectes platessa 9 0.002541986 0.002428850 0.002651954
10 Zz_Gadus morhua 10 0.000000000 0.000000000 0.000000000
amp_eff_output_extract(M5_output) Species Pre-PCR Post-PCR ALR Post-PCR_est Post-PCR_est_2.5%_CI Post-PCR_est_97.5%_CI
1 Brosme brosme 0.08923200 0.05556938 0.01337365 0.05556508 0.05550223 0.05563003
2 Cyclopterus lumpus 0.17871590 0.07901771 0.70793133 0.07901734 0.07895966 0.07906228
3 Hippoglossoides platessoides 0.10093796 0.10672923 0.13663999 0.10672738 0.10668778 0.10676739
4 Leptoclinus maculatus 0.05519582 0.24240363 -0.46697893 0.24240216 0.24245941 0.24236600
5 Mallotus villosus 0.14545023 0.08065732 0.50196793 0.08065692 0.08059503 0.08071096
6 Maurolicus muelleri 0.10501282 0.12690236 0.17621634 0.12689617 0.12687310 0.12692940
7 Myoxocephalus scorpius 0.13199579 0.08596141 0.40490397 0.08595708 0.08591673 0.08599369
8 Pholis gunnellus 0.06633870 0.06898988 -0.28309260 0.06898689 0.06891992 0.06905006
9 Pleuronectes platessa 0.03907419 0.05093104 -0.81240387 0.05092413 0.05085598 0.05098541
10 Zz_Gadus morhua 0.08804659 0.10283804 0.00000000 0.10286685 0.10323015 0.10250478
extract_ini_prop(M5_output) Species 2019629_11 2019629_12 2019629_13 2019629_14 2019629_15 2019629_16 2019629_19 2019629_20 2019629_21 2019629_22 2019629_23 2019629_24 2019629_27 2019629_28 2019629_29 2019629_3 2019629_30 2019629_31 2019629_32 2019629_4 2019629_5 2019629_6 2019629_7 2019629_8 2020620_03 2020620_04 2020620_05 2020620_06 2020620_07 2020620_08 2020620_11 2020620_12 2020620_13 2020620_14 2020620_15 2020620_16 2020620_19 2020620_20 2020620_21 2020620_22 2020620_23 2020620_24 2020620_27 2020620_28 2020620_29 2020620_30 2020620_31 2020620_32 2021624_10 2021624_11 2021624_14 2021624_15 2021624_16 2021624_17 2021624_18 2021624_19 2021624_20 2021624_21 2021624_22 2021624_25 2021624_26 2021624_27 2021624_28 2021624_29 2021624_3 2021624_30 2021624_31 2021624_32 2021624_33 2021624_36 2021624_37 2021624_38 2021624_39 2021624_4 2021624_40 2021624_41 2021624_42 2021624_43 2021624_44 2021624_5 2021624_6 2021624_7 2021624_8 2021624_9
1 Brosme brosme 8.899268e-07 0.0012240364 1.042267e-06 1.922490e-05 3.780674e-06 0.0010829967 3.965325e-07 2.474055e-05 0.0009503978 1.041862e-05 7.865112e-04 0.0047205174 1.628677e-05 1.951041e-04 7.453361e-05 7.212880e-05 7.619942e-07 2.443469e-03 1.683900e-04 2.230352e-06 6.612024e-04 5.969334e-06 6.128115e-04 2.264513e-05 1.328135e-04 9.321558e-02 0.0006900938 2.657769e-04 9.342666e-06 1.521788e-05 8.093014e-05 2.234054e-04 2.748349e-06 5.608353e-05 1.393465e-06 8.589425e-07 1.051068e-04 1.363399e-04 7.941231e-06 4.327355e-05 1.625195e-05 4.271998e-06 7.307332e-06 2.944117e-06 7.631102e-07 4.231681e-05 4.311539e-06 1.180893e-06 1.721898e-05 4.650411e-06 2.151492e-04 4.848335e-04 9.615915e-05 7.728038e-04 1.036547e-05 2.681427e-04 1.283245e-04 0.0005083416 4.040841e-06 9.084474e-06 3.648641e-07 5.239149e-06 5.544111e-06 2.434630e-05 3.798007e-06 3.079500e-05 5.698980e-07 8.518596e-06 1.799305e-07 2.987980e-05 4.706072e-06 2.519598e-06 2.166001e-06 2.329782e-05 2.223640e-05 7.804576e-06 7.082180e-05 4.358220e-07 5.827103e-06 0.0020883540 6.957020e-06 5.865091e-06 2.104683e-04 1.305374e-04
2 Cyclopterus lumpus 2.919538e-05 0.0014473378 5.336773e-04 1.797324e-04 4.530279e-06 0.0013374001 5.688115e-05 4.853673e-03 0.0009742194 3.417726e-04 1.945432e-03 0.0030529618 2.256677e-04 2.521097e-04 9.577568e-04 9.921770e-04 8.798618e-01 1.305037e-04 2.308205e-04 5.325412e-05 2.750496e-05 7.327713e-06 1.489298e-05 1.856939e-02 3.895708e-04 1.306513e-04 0.0009066468 3.661338e-04 4.831527e-04 1.853757e-05 1.011022e-04 1.650832e-05 4.107570e-03 4.207611e-06 6.927241e-04 8.834108e-07 7.496838e-06 1.637061e-04 1.084314e-05 1.275597e-04 2.233806e-05 5.528296e-06 9.251954e-06 4.153004e-06 1.328252e-04 1.255226e-04 5.618630e-06 1.387832e-06 5.253886e-04 5.305890e-04 3.976404e-06 1.680619e-05 1.186082e-04 3.470349e-04 1.409075e-05 3.104788e-04 9.106843e-06 0.0222727689 4.484262e-06 8.169381e-05 2.280210e-05 3.256419e-07 4.097446e-05 6.404621e-07 3.023530e-04 9.695275e-05 3.236947e-05 9.618379e-05 3.723580e-05 4.165225e-05 9.617123e-04 1.465727e-04 2.313948e-01 3.114824e-05 6.493447e-04 1.013038e-05 1.927447e-02 4.659254e-07 7.007108e-06 0.0027186114 8.773267e-06 2.965392e-04 1.349750e-03 1.833444e-04
3 Hippoglossoides platessoides 5.738314e-02 0.0615242487 9.974266e-01 8.787644e-01 2.679446e-06 0.0007238668 9.995591e-01 9.778144e-01 0.5431545264 5.591638e-01 9.484325e-01 0.0028030128 9.080586e-01 2.458623e-03 8.397104e-03 4.944131e-01 5.921020e-02 6.644918e-05 2.170388e-03 1.050389e-04 3.337518e-03 4.501894e-01 2.368446e-04 5.480096e-03 7.678550e-01 6.429044e-01 0.0004369982 5.043083e-01 5.529744e-01 8.076190e-01 4.498774e-01 7.939347e-06 1.738152e-03 4.088839e-01 1.358367e-04 7.003190e-01 8.699276e-01 8.258138e-05 9.811296e-01 2.470804e-01 3.682781e-04 3.120202e-04 6.194300e-01 6.732962e-01 3.815720e-01 3.770115e-01 5.692524e-01 9.991629e-01 3.481612e-03 3.449270e-04 2.108317e-01 8.510460e-06 6.248916e-05 6.600536e-01 9.875866e-01 2.134188e-01 5.900670e-01 0.0420693404 9.983522e-01 7.129130e-01 9.462512e-01 1.984057e-01 8.384808e-01 9.003669e-01 8.851950e-01 9.508328e-01 8.816935e-01 7.391170e-01 6.689621e-01 8.137417e-01 1.558195e-01 7.923514e-01 6.024804e-01 9.542606e-01 6.775471e-01 9.714385e-01 7.191074e-01 9.995189e-01 9.722317e-01 0.0015221718 9.320029e-02 1.113360e-01 4.069733e-01 5.964881e-01
4 Leptoclinus maculatus 2.681543e-04 0.0155468009 1.009643e-04 6.780723e-02 1.118263e-06 0.0002359490 5.225417e-05 6.961440e-04 0.4475405730 1.328204e-01 3.655182e-03 0.0006903948 2.488705e-05 3.800723e-05 2.133120e-04 1.140364e-02 2.185007e-02 1.832201e-05 3.588701e-05 1.557056e-02 5.271999e-04 4.155671e-02 2.249938e-06 8.539748e-06 4.008181e-05 6.286601e-03 0.0001388672 6.986753e-02 9.780176e-03 3.209804e-06 1.951927e-05 2.479155e-06 9.883490e-07 6.135482e-07 1.515391e-05 2.729661e-07 1.167883e-06 2.527874e-05 1.667257e-06 8.659975e-04 2.972069e-06 8.755032e-07 1.524256e-06 6.288523e-07 1.981547e-07 1.006456e-02 3.004007e-02 3.781046e-07 5.503716e-05 2.577468e-05 6.101552e-06 2.800301e-06 1.733911e-05 2.609932e-06 2.272711e-06 8.391785e-05 1.467142e-06 0.0023602559 1.190993e-06 9.376910e-04 6.653622e-08 5.063840e-08 2.359672e-03 1.681568e-06 1.692133e-02 7.604056e-08 5.772768e-05 3.348338e-04 5.047608e-08 5.325515e-03 1.817625e-01 1.570977e-05 5.169367e-03 5.289106e-06 2.189330e-02 1.578054e-06 1.261610e-03 1.287722e-07 1.123395e-06 0.0005135151 4.169975e-03 5.979770e-02 3.086412e-05 1.326582e-06
5 Mallotus villosus 9.365262e-01 0.8874701813 1.826850e-03 3.134626e-04 8.930997e-01 0.1363993667 2.208901e-04 1.461766e-02 0.0009486937 5.720560e-04 1.418995e-03 0.2205986831 3.904238e-04 2.563096e-02 5.240618e-03 4.404456e-01 2.371387e-02 1.034010e-04 2.231686e-02 9.308618e-01 9.913750e-01 8.614331e-02 7.768678e-01 9.743107e-01 2.010899e-02 1.198555e-01 0.0498616024 4.325718e-02 1.062241e-05 1.531718e-05 5.145639e-01 8.145780e-01 2.671345e-01 5.468838e-01 7.790744e-01 2.531107e-04 5.188547e-02 5.984069e-03 5.338211e-04 7.044423e-01 8.380245e-01 9.805164e-01 2.034178e-01 2.951631e-01 2.577954e-01 5.442853e-01 2.870242e-01 2.609164e-04 8.256202e-01 5.591848e-01 6.658352e-01 4.907144e-01 7.308823e-01 5.698201e-04 3.716618e-04 7.382127e-01 3.220082e-01 0.1436335277 1.497590e-03 2.698449e-01 5.197803e-02 8.000427e-01 1.332948e-01 9.494819e-02 7.651233e-04 3.391815e-02 1.083665e-01 2.551093e-01 3.309559e-01 1.256495e-01 2.954947e-01 4.042108e-04 7.249885e-02 5.500990e-03 1.116168e-03 1.149843e-03 1.746639e-01 4.693406e-04 4.486039e-04 0.2685564891 8.273896e-01 7.159089e-01 1.038771e-02 2.716737e-01
6 Maurolicus muelleri 5.948571e-07 0.0009956537 7.723331e-07 1.032052e-05 2.624982e-06 0.0006445469 1.036786e-04 1.365057e-05 0.0007110566 6.527069e-06 1.686644e-04 0.0001185058 8.941288e-06 2.150699e-03 4.821577e-05 1.832408e-05 4.463056e-07 5.920909e-05 1.019786e-04 1.310800e-06 1.356049e-03 3.206580e-06 1.008840e-04 1.079244e-03 7.007422e-05 2.795071e-06 0.0003923484 7.175888e-06 5.159240e-06 8.280687e-06 5.101508e-05 7.296645e-06 1.929889e-06 1.786000e-06 9.093830e-07 5.821201e-07 3.067899e-06 7.563422e-05 4.729104e-06 1.484317e-06 9.474521e-06 2.509979e-06 4.169068e-06 1.819773e-06 4.867883e-07 2.232347e-05 2.405536e-06 8.106802e-07 1.914634e-04 2.692941e-06 1.560097e-06 6.954292e-06 5.432129e-05 7.632040e-06 6.032738e-06 1.980294e-04 4.010914e-06 0.0003385316 2.433547e-06 3.025737e-07 2.051844e-07 1.454399e-07 2.882737e-06 5.925065e-06 2.522791e-06 2.207816e-07 3.247027e-07 1.159088e-07 1.135198e-07 1.109747e-06 2.897538e-06 1.607127e-06 1.273447e-06 3.806201e-04 1.367703e-05 4.317279e-06 1.187403e-05 2.707301e-07 3.195029e-06 0.0013222375 4.384572e-06 2.358389e-04 4.104295e-06 3.525071e-06
7 Myoxocephalus scorpius 8.852046e-07 0.0011523035 8.444219e-05 3.874270e-05 4.077149e-06 0.0009936395 3.545839e-07 2.141366e-05 0.0009380954 2.294958e-04 2.004243e-04 0.0001818846 1.590975e-05 1.869233e-04 6.655878e-04 2.198569e-04 1.827848e-05 8.781624e-05 1.662487e-04 3.562797e-05 2.013174e-05 5.499634e-06 1.130048e-05 2.244313e-05 4.066878e-04 1.864358e-04 0.0006276932 1.227033e-05 1.595670e-04 1.921149e-03 7.180689e-05 2.121491e-04 7.517249e-04 3.154075e-06 9.871165e-05 7.596855e-07 1.004606e-04 1.269256e-04 8.067622e-06 8.839183e-05 1.413117e-05 4.480014e-06 1.825189e-04 3.180457e-06 7.339785e-07 2.435431e-06 7.207187e-05 2.188859e-04 3.614167e-04 4.516045e-06 8.087073e-05 1.300586e-05 2.176722e-03 1.331843e-05 1.117239e-05 2.420110e-04 1.239042e-04 0.0005204736 3.415674e-06 1.800827e-05 7.422479e-06 2.394348e-07 5.297894e-06 3.574112e-05 9.699688e-05 4.156578e-05 2.200840e-05 2.140814e-05 1.751671e-07 1.776261e-06 1.177235e-04 2.386786e-06 9.081924e-05 6.875476e-04 4.505527e-04 7.915263e-06 2.081351e-04 4.203895e-07 5.691726e-06 0.0022283318 6.896071e-06 5.798281e-06 1.997100e-04 5.792808e-06
8 Pholis gunnellus 7.059205e-04 0.0009618224 7.917257e-07 1.202424e-05 1.066038e-01 0.0006511243 3.129499e-07 1.602348e-05 0.0007413184 2.422393e-01 5.887824e-06 0.0001247841 1.038025e-05 2.489906e-03 4.196084e-04 2.794973e-04 1.173551e-05 6.983677e-01 1.136319e-04 1.071932e-05 1.420034e-05 3.319897e-01 7.330971e-06 1.912315e-05 1.084206e-01 9.616156e-02 0.0266301182 2.979859e-01 3.081850e-01 1.431351e-01 5.434548e-05 7.999552e-06 7.262099e-01 7.019647e-05 2.198047e-01 2.994082e-01 4.205298e-06 8.477937e-05 2.886255e-04 8.016032e-03 1.115326e-05 2.688582e-06 1.606747e-01 2.060107e-06 3.604583e-01 2.037799e-02 5.125820e-02 3.218686e-04 1.058215e-01 4.367776e-01 1.823904e-04 4.994272e-01 5.977045e-05 1.380236e-01 6.853097e-06 4.265937e-02 4.823061e-06 0.0097533696 2.666919e-06 3.537285e-03 3.636196e-05 1.023991e-05 5.472663e-03 2.246829e-03 8.417469e-02 2.975679e-05 5.164589e-03 3.465823e-03 3.663503e-05 1.064663e-02 3.518208e-01 2.057036e-01 6.979938e-02 1.634732e-05 1.166758e-01 5.636485e-06 1.970552e-02 3.117552e-07 3.785330e-06 0.0645488033 4.976758e-02 1.062619e-01 5.751794e-01 8.355668e-02
9 Pleuronectes platessa 5.334787e-07 0.0009057409 6.893763e-07 1.344945e-06 2.495698e-06 0.0005270603 2.533227e-07 1.411687e-05 0.0007645125 6.164361e-06 4.806503e-06 0.0001122760 8.641856e-06 1.071158e-04 4.315525e-05 2.258109e-06 4.033310e-07 5.423188e-05 9.121195e-05 1.309614e-06 1.261142e-05 3.185476e-06 6.712996e-06 1.505939e-05 3.595146e-06 2.539116e-06 0.0003822318 7.212260e-06 5.331849e-06 8.436009e-06 4.640582e-05 6.821539e-06 1.946539e-06 1.800529e-06 8.129219e-07 5.616438e-07 3.348086e-06 6.909670e-05 4.665315e-06 1.385508e-06 8.706286e-06 2.452510e-06 4.090472e-06 1.707648e-06 4.373505e-07 1.356827e-06 2.234426e-06 7.685865e-07 9.126434e-06 2.466325e-06 1.457687e-06 7.911738e-06 4.879562e-05 7.706241e-06 5.744288e-06 1.791709e-04 3.700201e-06 0.0002856802 2.448074e-06 2.908799e-07 1.855061e-07 1.286403e-07 2.255533e-07 2.931046e-07 2.165811e-06 2.123048e-07 3.052162e-07 1.134980e-07 1.068183e-07 9.585945e-07 2.803557e-06 1.539479e-06 1.234830e-06 1.273662e-05 1.310813e-05 4.223979e-06 8.328097e-07 2.385417e-07 3.155211e-06 0.0012092314 4.051279e-06 3.519091e-06 3.593409e-06 3.536758e-06
10 Zz_Gadus morhua 5.084531e-03 0.0287718744 2.415526e-05 5.285352e-02 2.751267e-04 0.8574040498 5.917370e-06 1.928207e-03 0.0032766068 6.461011e-02 4.338162e-02 0.7675969795 9.124025e-02 9.664906e-01 9.839401e-01 5.215343e-02 1.533240e-02 2.986689e-01 9.746046e-01 5.335819e-02 2.668562e-03 9.009566e-02 2.221392e-01 4.727525e-04 1.025725e-01 4.125398e-02 0.9199334000 8.392245e-02 1.283872e-01 4.725578e-02 3.513355e-02 1.849374e-01 5.053410e-05 4.409445e-02 1.753209e-04 1.572949e-05 7.796204e-02 9.932516e-01 1.801004e-02 3.933324e-02 1.615222e-01 1.914878e-02 1.626862e-02 3.152422e-02 3.882375e-05 4.806677e-02 6.233845e-02 3.087369e-05 6.391697e-02 3.121941e-03 1.228416e-01 9.317576e-03 2.664834e-01 2.002019e-01 1.198523e-02 4.427452e-03 8.764947e-02 0.7782577106 1.295120e-04 1.265774e-02 1.703377e-03 1.535240e-03 2.033716e-02 2.369477e-03 1.253600e-02 1.504943e-02 4.662175e-03 1.846731e-03 7.566509e-06 4.456129e-02 1.401265e-02 1.370422e-03 1.856169e-02 3.908138e-02 1.816187e-01 2.737008e-02 6.569551e-02 9.441208e-06 2.728992e-02 0.6552922546 2.544152e-02 6.147987e-03 5.661108e-03 4.795348e-02
extract_ini_conc(M5_output)# A tibble: 840 × 5
Species Sample Conc `Conc_2.5%CI` `Conc_97.5%CI`
<chr> <chr> <dbl> <dbl> <dbl>
1 Brosme brosme 2019629_11 -8.65 -14.3 -5.08
2 Brosme brosme 2019629_12 -3.16 -10.8 2.11
3 Brosme brosme 2019629_13 -3.14 -10.6 2.11
4 Brosme brosme 2019629_14 -7.92 -10.6 -5.82
5 Brosme brosme 2019629_15 -4.29 -11.2 0.437
6 Brosme brosme 2019629_16 -6.67 -12.7 -3.02
7 Brosme brosme 2019629_19 -2.70 -10.2 3.02
8 Brosme brosme 2019629_20 -4.36 -11.5 0.515
9 Brosme brosme 2019629_21 -1.24 -10.1 6.19
10 Brosme brosme 2019629_22 -8.73 -14.6 -5.25
# ℹ 830 more rows
5.5 Plot outputs
plot_amp_eff(M5_output)bar_plot_est_ini_prop(M5_output)plot_est_ini_conc(M5_output)Guri et al., 2024 that are used in this script.
5.6 Diagnose models
diagnose_model(M5_output)6 All functions
For step 1:
load_model(model)
For step 2:
prep_stan_M1(...)
prep_stan_M2(...)
prep_stan_M3(...)
prep_stan_M4(...)
prep_stan_M5(...)
For step 3:
Run_Model(stan_object, stan_data)
For step 4:
extract_qpcr_param(model_output)
extract_est_conc(model_output)
extract_amp_efficiecy(model_output)
amp_eff_output_extract(model_output)
extract_ini_prop(model_output)
extract_ini_conc(model_output)
For step 5:
plot_qpcr_prob_det(model_output,xmin_log, xmax_log)
plot_qpcr_cont_mod(model_output,xmin_log, xmax_log)
plot_qpcr_curves(model_output, xmin_log, xmax_log
plot_qpcr_cont_mod_plate_specific(model_output, xmin_log, xmax_log)
plot_est_conc(model_output)
plot_amp_eff(model_output)
bar_plot_est_ini_prop(model_output)
plot_est_ini_conc(model_output, k = 2)
diagnose_model()